﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Maticsoft.Web
{
    public partial class study : System.Web.UI.Page
    {
        BLL.studentInfo s = new BLL.studentInfo();
        DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["type"] != null)
                {
                    string type =Server.UrlDecode(Request.QueryString["type"].ToString());
                    //[sCount] ,[mCount] ,[jCount] ,[sScore] ,[mScore] ,[jScore] 
                    //type = "机关单位";                    
                    Bind(type);
                    //SubmitQuestion();
                }
            }

        }
        private void Bind(string type)
        {
            Maticsoft.BLL.singleInfo sm = new BLL.singleInfo();
            //ds = sm.GetList(" stutype='" + type + "' order by newid()");
            ds = sm.GetList(" stutype='" + type + "' order by singleId");
            this.DataList1.DataSource = ds;
            this.DataList1.DataBind();
            Maticsoft.BLL.mostInfo mm = new BLL.mostInfo();
            //ds = mm.GetList(" stutype='" + type + "' order by newid()");
            ds = mm.GetList(" stutype='" + type + "' order by mostId");
            this.DataList2.DataSource = ds;
            this.DataList2.DataBind();
            Maticsoft.BLL.judgeInfo jm = new BLL.judgeInfo();
            //ds = jm.GetList(" stutype='" + type + "' order by newid()");
            ds = jm.GetList(" stutype='" + type + "' order by judgeId");
            this.DataList3.DataSource = ds;
            this.DataList3.DataBind();
            Maticsoft.BLL.answerinfo am = new BLL.answerinfo();
            //ds = jm.GetList(" stutype='" + type + "' order by newid()");
            ds = am.GetList(" stutype='" + type + "' order by aid");
            this.DataList4.DataSource = ds;
            this.DataList4.DataBind();
        }

        //提交答案
        protected void btn_submit_Click(object sender, EventArgs e)
        {
            //保存时间
        }
        
        private void SubmitQuestion()
        {            
            //km.DeleteByWhere(" stuId=" + stuId + " and type = 1 ");//删除此学生的所有已提交单项选择答案
            foreach (DataListItem item in this.DataList1.Items)
            {
                //Label lbl_title = (Label)item.FindControl("lbl_title");
                Label lbl_singleId = (Label)item.FindControl("lbl_singleId");
                RadioButton rdoA = (RadioButton)item.FindControl("rdoA");
                RadioButton rdoB = (RadioButton)item.FindControl("rdoB");
                RadioButton rdoC = (RadioButton)item.FindControl("rdoC");
                RadioButton rdoD = (RadioButton)item.FindControl("rdoD");
                string key = ((HiddenField)item.FindControl("hfkey")).Value;
                if (key == "A") rdoA.Checked = true;
                if (key == "B") rdoB.Checked = true;
                if (key == "C") rdoC.Checked = true;
                if (key == "D") rdoD.Checked = true;
                
                
            }
            foreach (DataListItem item in this.DataList2.Items)
            {                
                CheckBox cboA = (CheckBox)item.FindControl("cboA");
                CheckBox cboB = (CheckBox)item.FindControl("cboB");
                CheckBox cboC = (CheckBox)item.FindControl("cboC");
                CheckBox cboD = (CheckBox)item.FindControl("cboD");
                string key = ((HiddenField)item.FindControl("hfkey")).Value;              

                string result = "";
                if (key.Contains("A")) cboA.Checked = true;
                if (key.Contains("B")) cboB.Checked = true;
                if (key.Contains("C")) cboC.Checked = true;
                if (key.Contains("D")) cboD.Checked = true;
                

            }
            foreach (DataListItem item in this.DataList3.Items)
            {                
                RadioButton rdoYes = (RadioButton)item.FindControl("rdoYes");
                RadioButton rdoNo = (RadioButton)item.FindControl("rdoNo");
                string key = ((HiddenField)item.FindControl("hfkey")).Value;
                if (key == "正确") rdoYes.Checked = true;
                if (key == "错误") rdoNo.Checked = true;
            }
        }

        protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                HiddenField h = e.Item.FindControl("hfmark") as HiddenField;
                Button b = e.Item.FindControl("btnMark") as Button;
                Label l3 = e.Item.FindControl("Label5") as Label;
                Label l4 = e.Item.FindControl("Label6") as Label;
                RadioButton r4 = e.Item.FindControl("rdoD") as RadioButton;
                RadioButton r3 = e.Item.FindControl("rdoC") as RadioButton;
                if (l4 != null)
                {
                    if (l4.Text.Trim() == "D：") { l4.Visible = false; if (r4 != null)r4.Visible = false; }
                }
                if (l3 != null)
                {
                    if (l3.Text.Trim() == "C：") { l3.Visible = false; if (r3 != null)r3.Visible = false; }
                }
                if (b != null && h != null)
                {
                    b.Attributes.Add("onclick", "javascript:return changeColor(this,'" + h.ClientID + "');");                    
                }
            }
        }

    }
}